package com.ruoyi.web.controller.system;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.net.URL;

/**
 * @author 48824
 */
public class htmlParseUtils {
    public static void main(String[] args) throws Exception {
//        //获取请求
//        String URL = "https://www.kongfz.com/";
//        //获取请求内容 解析网页返回Document对象
//        Document parse = Jsoup.parse(new URL(URL), 3000);
//        //获取网页内容
//        Elements elementsByClass = parse.getElementsByClass("layer-slide gallery-book-slide");
//        System.out.println(elementsByClass.html());


        //获取请求
        String URL2 = "https://www.kongfz.com/1004/";
        Document parse2 = Jsoup.parse(new URL(URL2), 3000);
        Elements elementsByClass = parse2.getElementsByClass("item clearfix");
        for (Element elements: elementsByClass) {
            Elements elementsByClass1 = elements.getElementsByClass("link"); //书的名称
            System.out.println(elementsByClass1.html());
            String attr = elements.getElementsByTag("img").eq(0).attr("src");
            System.out.println(attr);
            Elements elementsByClass4 = elements.getElementsByClass("zl-isbn-info");
            System.out.println(elementsByClass4.text());
            String text = elements.getElementsByClass("book-type").eq(0).text(); //新书
            String elementsByClass2 = elements.getElementsByClass("price").eq(0).text(); //新书价格
            System.out.println(text);
            System.out.println(elementsByClass2);
            String text1 = elements.getElementsByClass("book-type").eq(1).text(); //老书
            String elementsByClass3 = elements.getElementsByClass("price").eq(1).text(); //书价格
            System.out.println(text1);
            System.out.println(elementsByClass3);
            System.out.println("elementsByClass3------------------------------------");

        }

        /*https://www.kongfz.com/1004/?page=2*/
    }
}
